package com.chebaohui.iqs.service.impl.deal.taiping.ev;

import com.alibaba.fastjson.JSONObject;
import com.chebaohui.iqs.config.CompanyValue;
import com.chebaohui.iqs.service.impl.deal.taiping.DirectTp;
import com.chebaohui.iqs.service.impl.deal.taiping.PublicNew;
import com.chebaohui.iqs.service.impl.deal.taiping.RequestHead;
import com.chebaohui.iqs.service.impl.deal.taiping.ResTaiPing;

/**
 * E07-上年投保信息查询
 * 
 * @author xielonghai
 * @version 2016-07-07
 */
public class E07Request {
	/**
	 * 上年保单查询接口方法
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param orderNo
	 *            订单号--业务单号
	 * @param checkMsg
	 *            校验信息--车主身份证号
	 * @return
	 */
	public static ResTaiPing requestE07(String session, String orderNo, String checkMsg) {
		String value = CompanyValue.TAIPING + ":辅助接口--根据订单号:" + orderNo + ",车主身份证号:" + checkMsg + ",获取上年保单详情";

		String[] key = { "carOwner"// 车主信息（carOwner）
				, "applicant"// 投保人信息（applicant）
				, "insured"// 被保险人信息（insured）
		};

		return DirectTp.request(value, PublicNew.REQUEST_URL + "/insureHistory", getRequest(session, orderNo, checkMsg),
				key);
	}

	/**
	 * 获取--E07-上年保单查询------请求参数
	 * 
	 * @param session
	 *            会话ID--初始为空,后续调用为上次request返回
	 * @param orderNo
	 *            订单号
	 * @param checkMsg
	 *            车主身份证号
	 * @return
	 */
	private static String getRequest(String session, String orderNo, String checkMsg) {
		JSONObject head = RequestHead.getHead(session);
		String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
		request = request + "\n" + "<request>";
		request = request + "\n" + "<head>";

		request = request + "\n\t" + "<msgId>" + head.getString("msgId") + "</msgId>";
		request = request + "\n\t" + "<timeStamp>" + head.getString("timeStamp") + "</timeStamp>";
		request = request + "\n\t" + "<session>" + head.getString("session") + "</session>";
		request = request + "\n\t" + "<userCode>" + head.getString("userCode") + "</userCode>";
		// request = request + "\n\t" + "<clientName>" +
		// head.getString("clientName") + "</clientName>";

		request = request + "\n" + "</head>";
		request = request + "\n" + "<body>";

		request = request + "\n\t" + "<order>";
		request = request + "\n\t\t" + "<orderNo>" + orderNo + "</orderNo>";// 订单号
		request = request + "\n\t\t" + "<checkMsg>" + checkMsg + "</checkMsg>";// 车主身份证号
		request = request + "\n\t" + "</order>";

		request = request + "\n" + "</body>";
		request = request + "\n" + "</request>";
		return request;
	}

}
